<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>审批人列表</title>
    <script type="text/javascript">
      var editAuditorWin;
      var newAuditorWin;
      var auditorId;
      Ext.onReady(function(){
        //审批人列表---------------------------------------------------------
        //生成有关审批人的Grid
        var auditorDS = new Ext.data.Store({
          paramNames: {
            start: "start",
            limit: "limit"
          },
          baseParams: {
            start: 0,
            limit: pageSize
          },
          proxy: new Ext.data.HttpProxy({
            url: '/auditor/getAuditors'
          }),
          reader: new Ext.data.JsonReader({
            totalProperty: 'totalProperty',
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'login_id'
            }, {
              name: 'name'
            }, {
              name: 'department_name',
              mapping:'department.name'
            }, {
              name: 'phone'
            }, {
              name: 'mobile'
            }, {
              name: 'email'
            }, {
              name: 'unit_price_ceiling'
            }, {
              name: 'amount_ceiling'
            },{
              name:'auditing_status'
            },{
              name:'role_name',
              mapping:'role',
              convert:function(value){
                if(value == ""){
                  return "";
                }else{
                  return value.name;
                }
              }
            },{
              name:'is_chief',
              convert:function(value){
                if(value == 1){
                  return "处长";
                }else{
                  return "";
                }
              }
            },{
              name:'is_admin',
              convert:function(value){
                if(value == 1){
                  return "管理员";
                }else{
                  return "";
                }
              }
            },{
              name:'auditor_type',
              convert:function(value){
                if(value == '0'){
                  return "设备";
                }else{
                  return "家具";
                }
              }
            }])
        });
        var stateStore = new Ext.data.ArrayStore({
          fields: ['state'],
          data : stateDataArray
        });
        var auditorSM = new Ext.grid.CheckboxSelectionModel();
        var auditorCM = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(),auditorSM,{
            header: '审批人编号',
            dataIndex: 'login_id',
            width:90
          }, {
            header: '审批人姓名',
            dataIndex: 'name',
            width:90
          }, {
            header: '部门',
            dataIndex: 'department_name',
            width:130
          }, {
            header: '固定电话',
            dataIndex: 'phone',
            width:130
          }, {
            header: '移动电话',
            dataIndex: 'mobile',
            width:110
          }, {
            header: '管理单价上限',
            dataIndex: 'unit_price_ceiling',
            align: 'right',
            renderer: Ext.util.Format.numberRenderer('0,000.00'),
            width:90
          }, {
            header: '管理总额上限',
            dataIndex: 'amount_ceiling',
            align: 'right',
            renderer: Ext.util.Format.numberRenderer('0,000.00'),
            width:90
          },{
            header:'审批类型',
            dataIndex:'auditor_type',
            width:80
          },{
            header:'管理员?',
            dataIndex:'is_admin',
            width:70
          },{
            header:'处长?',
            dataIndex:'is_chief',
            width:50
          },{
            header:'角色',
            dataIndex:'role_name',
            width:110
          },{
            header:'审批状态',
            dataIndex:'auditing_status',
            renderer:auditingRender,
            width:80
          }]);
        var auditorGrid =  new Ext.grid.GridPanel({
          ds: auditorDS,
          cm: auditorCM,
          sm: auditorSM,
          width: screenWidth-330,
          height: screenHeight-320,
          iconCls: 'icon-grid',loadMask: true,
          //collapsible: true,
          //animCollapse: false,
          //frame: true,
          //title: '客户列表',
          tbar:[{
              text:'添加',
              width:50,
              iconCls:'addItem',
              handler:function(){
                newAuditorWin = new Ext.Window({
                  layout: 'fit',
                  width:767,
                  height:245,
                  closeAction: 'destroy',
                  plain: true,
                  modal: true,
                  constrain:true,
                  //modal: true,
                  title: '新增审批人',
                  autoLoad: {
                    url: "/auditor/newAuditor",
                    scripts: true
                  }
                });
                newAuditorWin.on("destroy",function(){
                  auditorDS.reload();
                });
                newAuditorWin.resizable = false;
                newAuditorWin.show();
              }
            },'-',{
              text: '编辑',
              width:50,
              iconCls:'editItem',
              handler:function(){
                var records = auditorGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.alert('提示信息', '请先选中一条记录后，再编辑。');
                }else{
                  //把表单添加到窗口中
                  auditorId = records[0].get('id');
                  editAuditorWin = new Ext.Window({
                    title: '编辑审批人信息',
                    layout:'fit',
                    width:767,
                    height:245,
                    closeAction:'destroy',
                    constrain:true,
                    plain: true,
                    modal: true,
                    autoLoad: {
                      url: "/auditor/editAuditor?id=" + auditorId,
                      scripts: true
                    }
                  });
                  editAuditorWin.on("destroy",function(){
                    auditorDS.reload();
                  });
                  editAuditorWin.resizable = false;
                  editAuditorWin.show();
                }
              }
            },'-',{
              text:'启用',
              width:50,
              iconCls: 'yes',
              handler:function(){
                if(auditorGrid.getSelectionModel().hasSelection()){
                  var rs=auditorGrid.getSelectionModel().getSelections();
                  var ids=[];
                  var name='';
                  var n=0;
                  for(var i=0;i<rs.length;i++){
                    var data=rs[i].data;
                    ids.push(data.id);
                    name+=data.name+'<br>';
                    if(data.auditing_status!='禁用'){
                      n++
                    }
                  }
                  if(n==0){
                    var keys=Ext.util.JSON.encode(ids);
                    Ext.MessageBox.confirm('警告','确定启用以下审批人？<br><font color="red">' + name + '</font>',function (button){
                      if(button=='yes'){
                        Ext.Ajax.request({
                          url:'/auditor/applyPass',
                          method:'post',
                          success:function(response,opts){
                            var data = Ext.util.JSON.decode(response.responseText);
                            if(data.success&&data.info=='success') {
                              auditorDS.reload();
                              Ext.MessageBox.alert('提示信息', '已成功启用审批人。');
                            } else {
                              Ext.MessageBox.alert('提示信息', data.info);
                            }
                          },
                          params: {"id":keys}
                        });
                      }
                    });
                  }else{
                    Ext.MessageBox.alert('提示信息', '只能对<禁用>的审批人启用');
                  }
                            
                }else{
                  Ext.Msg.alert('提示信息','请选择审批人');
                }
              }
            },'-',{
              text:'禁用',
              width:50,
              iconCls: 'no',
              handler:function(){
                if(auditorGrid.getSelectionModel().hasSelection()){
                  var rs=auditorGrid.getSelectionModel().getSelections();
                  var ids=[];
                  var name='';
                  var n=0;
                  var m=0;
                  for(var i=0;i<rs.length;i++){
                    var data=rs[i].data;
                    ids.push(data.id);
                    if(data.is_admin==1){
                      n++;
                    }
                    if(data.auditing_status!='启用'){
                      m++
                    }
                    name+=data.name+'<br>';
                  }
                  if(n==0){
                    if(m==0){
                      var keys=Ext.util.JSON.encode(ids);
                      Ext.MessageBox.confirm('警告','确定禁用以下审批人？<br><font color="red">' + name + '</font>',function (button){
                        if(button=='yes'){
                          Ext.Ajax.request({
                            url:'/auditor/stopAuditor',
                            method:'post',
                            success:function(response,opts){
                              var data = Ext.util.JSON.decode(response.responseText);
                              if(data.success&&data.info=='success') {
                                auditorDS.reload();
                                Ext.MessageBox.alert('提示信息', '已成功禁用审批人。');
                              } else {
                                Ext.MessageBox.alert('提示信息', data.info);
                              }
                            },
                            params: {"id":keys}
                          });
                        }
                      });
                    }else{
                      Ext.MessageBox.alert('提示信息', '只能对<启用>的审批人禁用');
                    }
                                
                  }else{
                    Ext.MessageBox.alert('提示信息', '超级管理员不能禁用。');
                  }
                            
                }else{
                  Ext.Msg.alert('提示信息','请选择审批人');
                }
              }
            },'-',{
              text: '修改密码',
              width:50,
              iconCls:'editItem',
              handler:function(){
                var records = auditorGrid.getSelectionModel().getSelections();
                if(records.length==0){
                  Ext.MessageBox.alert('提示信息', '请先选中一条记录后，再编辑。');
                }else{
                  //把表单添加到窗口中
                  auditorId = records[0].get('id');
                  changePasswordWin = new Ext.Window({
                    title: '修改密码',
                    layout:'fit',
                    width:417,
                    height:140,
                    closeAction:'destroy',
                    constrain:true,
                    plain: true,
                    modal: true,
                    autoLoad: {
                      url: "/auditor/passwordForAuditor?id="+auditorId,
                      scripts: true
                    }
                  });
                  changePasswordWin.on("destroy",function(){
                    auditorDS.reload();
                  });
                  changePasswordWin.resizable = false;
                  changePasswordWin.show();
                }
              }
            },'-','检索条件','-',
            '审批人编号:',
            new Ext.form.TextField({
              name: 'auditor_number',
              width:100,
              id: 'auditor_number'
            }),
            '审批人姓名:',
            new Ext.form.TextField({
              name: 'auditor_name',
              width:100,
              id: 'auditor_name'
            }),
            '审批状态:',
            new Ext.form.ComboBox({
              store: stateStore,
              displayField:'state',
              typeAhead: true,
              mode: 'local',
              id:'state',
              forceSelection: true,
              triggerAction: 'all',
              valueField: 'state',
              emptyText:'',
              selectOnFocus:true
            }),
            {
              text:'搜索',
              iconCls: 'search',
              handler:function(){
                auditorDS.removeAll();
                auditorDS.baseParams.auditor_number = Ext.getCmp('auditor_number').getValue();
                auditorDS.baseParams.auditor_name = Ext.get('auditor_name').getValue();
                auditorDS.baseParams.state = Ext.get('state').getValue()
                auditorDS.load({
                  params:{
                    start: 0,
                    limit: pageSize
                  }
                })
              }
            }
          ],
          bbar: new Ext.PagingToolbar({
            pageSize: pageSize,
            store: auditorDS,
            displayInfo: true,
            displayMsg: "显示第 {0} 条到 {1} 条记录，一共 {2} 条",
            emptyMsg: "没有记录"
          })
        });
        auditorGrid.render('auditor_list');
        auditorDS.load();
      })
    </script>
  </head>
  <body>
    <div id="auditor_list"></div>
  </body>
</html>
